#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct iny{
	int c=0;
	int x=0;
	int y=0;
};
bool sor_t(iny x,iny y){
	return x.c>y.c;
}
int jdz(int a,int b){
	if(a>b){
		return a-b;
	}
	return b-a;	
	
}
int main(){
	int n,m,k,l=0,x1=0,y1=0,count=0;
	cin>>n>>m>>k;
	int a[n][m];
	iny s[n];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			if(a[i][j]>0){
				s[l].c=a[i][j];
				s[l].x=i+1;
				s[l].y=j+1;
				l++;
			}
		}
	}
	sort(s,s+l,sor_t);
	for(int i=0;i<l;i++){
		cout<<s[i].c<<" "<<s[i].x<<" "<<s[i].y<<endl;
	}
	for(int i=0;i<l;i++){
		if((jdz(s[i].x,x1)+jdz(s[i].y,y1)+1+s[i].y)>=k){
			count+=s[i].c;
			k-=(jdz(s[i].x,x1)+jdz(s[i].y,y1)+1+s[i].y);
			x1=s[i].x;
			y1=s[i].y;
		}
	}
	cout<<count;
} 
